from flask_login import LoginManager
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy

from com.redis_utils import RedisStore

db = SQLAlchemy()
migrate = Migrate()
redis_store = RedisStore()
login_manager = LoginManager()


def register_plugin(app):
    from qingdeng.orms import UserORM

    @login_manager.user_loader
    def user_loader(user_id):
        return UserORM.query.get(int(user_id))

    db.init_app(app)
    migrate.init_app(app, db)
    redis_store.init_app(app)
    login_manager.init_app(app)
